import dayjs from 'dayjs'
import type { orderForm } from '@/api/modules/types/assets'

export const rules = {
  PlaceDate: {
    required: true,
    message: '请选择订单日期',
    trigger: 'change',
  },
  AssetModelObjID: {
    required: true,
    message: '请选择型号',
    trigger: 'change',
  },
  AssetCodeYear: {
    required: true,
    message: '请选择年份',
    trigger: 'change',
  },
  AssetCodeBatch: {
    required: true,
    message: '请输入批次',
    trigger: 'change',
  },
  AssetCodeSNStart: {
    required: true,
    message: '请输入起始序列号',
    trigger: 'change',
  },
  AssetCodeSNEnd: {
    required: true,
    message: '请输入结束序列号',
    trigger: 'change',
  },
  RecAddress: {
    required: true,
    message: '请输入收货地点',
    trigger: 'change',
  },
  StipulateDate: {
    required: true,
    message: '约定发货日期',
    trigger: 'change',
  },
  Recipient: {
    required: true,
    message: '请输入联系人',
    trigger: 'change',
  },
  RecipientTel: {
    required: true,
    message: '请输入联系电话',
    trigger: 'change',
  },
  Remark: {
    required: true,
    message: '请输入备注',
    trigger: 'change',
  },
}

export function useInitForm(): { formData: Ref<orderForm>, initForm: () => void } {
  const getData = (): orderForm => ({
    Remark: '',
    PlaceDate: '',
    AssetModelObjID: '',
    AssetCodeYear: dayjs().year(),
    AssetCodeBatch: '',
    RecAddress: '',
    StipulateDate: '',
    Recipient: '',
    RecipientTel: '',
    OrderFormCode: '',
    ObjID: '',
    AssetCodeSNEnd: 0,
    AssetCodeSNStart: 0,
  })
  const formData = ref<orderForm>(getData())

  const initForm = () => {
    formData.value = getData()
  }

  return { formData, initForm }
}
